/*
mainwindow.h
(c) 2010 Yury Hamenkov
This file is part of qWordCards.

qWordCards is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

qWordCards is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with qWordCards. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QList>
#include <QTextEdit>
#include <QDir>
#include <QLabel>
#include <QTimer>
#include <QToolBar>
#include <QIcon>

#include "textlabel.h"
#include "dictionariesmanager.h"



namespace qWordCards {
	
	class Dictionary;
	class Word;
	
	class MainWindow : public QWidget {
	Q_OBJECT

	private:
		QSystemTrayIcon*		_tray;
		QMenu*					MNUTrayMenu;
		QAction*				ACTPlayPause;
		QAction*				ACTStop;
		QAction*				ACTPrevious;
		QAction*				ACTNext;
		QAction*				ACTQuit;
		QAction*				ACTSettings;
		QAction*				ACTUpdateDictionaries;
		QAction*				ACTAbout;
		QAction*				ACTDontShowThisWord;
		QAction*				ACTMarkThisWord;
		QAction*				ACTDownloadDictionaries;
		QAction*				ACTCloseWindow;
		QMenu*					MNUDictionariesList;


		QTimer*					TMRShowTimer;
		QTimer*					TMRWordChangeTimer;
		QTimer*					TMRShowTranslationTimer;

		


		TextLabel*				LBLTextLabel;
		QToolBar*				TBRToolBar;

		QIcon					ICNTray;
		QIcon					ICNPlay;
		QIcon					ICNPause;
		QIcon					ICNStop;
		QIcon					ICNNext;
		QIcon					ICNPrev;
		QIcon					ICNSelectDictionaries;
		QIcon					ICNSettings;
		QIcon					ICNRescanDictionaries;
		QIcon					ICNAbout;
		QIcon					ICNQuit;
		QIcon					ICNKnownWordTrue;
		QIcon					ICNKnownWordFalse;
		QIcon					ICNFavouriteWordTrue;
		QIcon					ICNFavouriteWordFalse;
		QIcon					ICNDownloadDictionaries;
		QIcon					ICNBook;
		QIcon					ICNBookQuestion;
		QIcon					ICNCloseWindow;
		
		DictionariesManager		_manager;


		enum State {
			Playing,
			Paused,
			Stopped,
			Scan,
			None
		};

		State currentState;

		void SetCurrentState(State newState);

		
		void UpdateWordStatus();

		void PrintWord (bool translation = true);
		bool NextWord();
		bool PreviousWord();
		


		bool playing;
		
		bool mousePressed;
		Qt::MouseButton pressedButton;
		QPoint mousePos;

		QList<Word> wordsQueue;
		int currentWordIndex;
		
		
		void ApplySettings();

	public:
		explicit MainWindow();
		~MainWindow();

	protected:
		virtual void moveEvent ( QMoveEvent * event );
		virtual void resizeEvent ( QResizeEvent * event );
		virtual void closeEvent ( QCloseEvent * event );
		virtual void mouseMoveEvent ( QMouseEvent * event );
		virtual void mousePressEvent ( QMouseEvent * event );
		virtual void mouseReleaseEvent ( QMouseEvent * event );

	signals:

	public slots:

	private slots:
		void sl_PlayPausePressed();
		void sl_StopPressed();
		void sl_PreviousPressed();
		void sl_NextPressed();
		void sl_QuitPressed();
		void sl_SettingsPressed();
		void sl_UpdateDictionariesPressed();
		void sl_AboutPressed();
		
		void sl_DontShowThisWordPressed();
		void sl_AddWordToFavouritesPressed();
		void sl_DownloadDictionariesPressed();
		void sl_CloseWindowPressed();
		

		void sl_ShowTimerTimeOut();
		void sl_WordChangeTimerTimeOut();
		void sl_ShowTranslationTimerTimeOut();
		
		void sl_DictionaryLoadingCompleted();

	};
}
#endif // MAINWINDOW_H
